/* @author cerimice */
package Persistencia.Definicion;

import Sistema.Configuracion;

import java.util.Date;
import java.io.Serializable;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.NamedQueries;

import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.JoinColumn;
import javax.persistence.Temporal;

@Entity
@Table(name="cierreOrdenServicio")
@NamedQueries
    ({
    @NamedQuery(name="cierreOrdenServicio.lista",               query="SELECT m FROM CierreOrdenServicio m ORDER BY m.clave"),
    @NamedQuery(name="cierreOrdenServicio.listaFecha",          query="SELECT m FROM CierreOrdenServicio m WHERE m.fecha BETWEEN :fechaInicio AND :fechaFinal ORDER BY m.clave"),
    @NamedQuery(name="cierreOrdenServicio.listaOrdenServicio",  query="SELECT m FROM CierreOrdenServicio m WHERE m.ordenServicio LIKE (:valor) ORDER BY m.clave"),
    @NamedQuery(name="cierreOrdenServicio.listaOrdenServicio2", query="SELECT m FROM CierreOrdenServicio m WHERE m.ordenServicio IN (:valor) ORDER BY m.clave")
    })

public class CierreOrdenServicio implements Serializable
    {
    @Id
    @Basic(optional=false)
    @Column(name="clave",nullable=false)
    private String clave;
    
    @Basic(optional=false)
    @Column(name="ordenServicio",nullable=false)
    private String ordenServicio;
    
    @Basic(optional=false)
    @Column(name="fecha",nullable=false)
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date fecha;
    
    @Basic(optional=false)
    @Column(name="ticket",nullable=false)
    private String ticket;
    
    @Basic(optional=false)
    @Column(name="montoManoObra",nullable=false)
    private float montoManoObra;
    
    @Basic(optional=false)
    @Column(name="montoRefacciones",nullable=false)
    private float montoRefacciones;
    
    @Basic(optional=false)
    @Column(name="comentario",nullable=true)
    private String comentario;
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ordenServicio",referencedColumnName="clave",insertable=false,updatable=false)
    private OrdenServicio objOrdenServicio;
    
    public CierreOrdenServicio()
        {clave = Configuracion.getFormatoClave().format(new Date());}
    
    public void setClave(String clave)                      {this.clave = clave;}
    public void setOrdenServico(String ordenServicio)       {this.ordenServicio = ordenServicio;}
    public void setFecha(Date fecha)                        {this.fecha = fecha;}
    public void setTicket(String ticket)                    {this.ticket = ticket;}
    public void setMontoManoObra(float montoManoObra)       {this.montoManoObra = montoManoObra;}
    public void setMontoRefacciones(float montoRefacciones) {this.montoRefacciones = montoRefacciones;}
    public void setComentario(String comentario)            {this.comentario = comentario;}
    
    
    public String   getClave()              {return clave;}
    public String   getOrdenServico()       {return ordenServicio;}
    public Date     getFecha()              {return fecha;}
    public String   getTicket()             {return ticket;}
    public float    getMontoManoObra()      {return montoManoObra;}
    public float    getMontoRefacciones()   {return montoRefacciones;}
    public String   getComentario()         {return comentario;}
    
    public float    getTotal()              {return montoManoObra+montoRefacciones;}
    
    public OrdenServicio getObjOrdenServicio()      {return objOrdenServicio;}
    
    @Override
    public String toString()                {return this.clave+" - "+this.ordenServicio;}
    }
